package com.x.erp.manage;

import java.util.Date;

import com.x.erp.util.ConstantTopic;
import com.x.rocketmq.RocketMqProducer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.x.erp.model.Car;
import com.x.erp.model.CarDel;
import com.x.erp.model.CarLog;
import com.x.framework.manage.BaseManage;

/**
 * 已删除车辆信息
 * @author pansong
 *
 */
@Service
public class CarDelManage extends BaseManage {

	private Logger logger = LoggerFactory.getLogger(this.getClass());

	@Autowired
	private RocketMqProducer rocketMqProducer;
	
	/**
	 * 新增已删除车辆信息
	 * @param carDel
	 * @return
	 * @throws Exception
	 */
	public CarDel insertCarDel(CarDel carDel, CarLog carLog) throws Exception {
		logger.info("carDelJson=================" + JSON.toJSONString(carDel));
		Date cDate = new Date();
		carDel.setCarDeleteTime(cDate);
		//新增已删除车辆信息
		carDel = this.insert(carDel);
		//将数据从car表中删除
		Car car = new Car();
		car.setCarId(carDel.getCarId());
		this.delete(car);
		//记录日志信息
		this.insert(carLog);
		try {
			rocketMqProducer.produceMessage(ConstantTopic.TOPIC_ERP_CAR, ConstantTopic.TAG_CAR_DELETE_CAR_INFO, car);
		} catch (Exception e) {
			logger.error("删除车辆信息插入rocketMq队列异常", e);
		}
		return carDel;
	}
	
	
}
